package com.cloudkinto.controller.system;

import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.system.SystemSetService;
import com.cloudkinto.vo.system.OmsSystemEntity;
import com.cloudkinto.vo.system.omp.OmpSystemEntity;
import com.cloudkinto.vo.system.wms.WmsSystemEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@Api(tags = "全局设置模块")
@RequestMapping("/api/admin/SystemSet")
public class SystemSetController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(SystemSetController.class);

    private final SystemSetService systemSetService;


    @UserSessionRequired
    @GetMapping("/omp/getSet")
    @ApiOperation(value = "获取omp全局设置", notes = "获取omp全局设置")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = OmpSystemEntity.class))
    public SingleResult getOmpSet() {
        return SingleResult.success("查询成功", systemSetService.getOmpSet(getTenantId("omp")));
    }


    @UserSessionRequired
    @PutMapping("/omp/set")
    @ApiOperation(value = "omp修改全局设置", notes = "omp修改全局设置")
    public SingleResult ompSet(@RequestBody @Validated OmpSystemEntity req) {
        systemSetService.ompSet(req, getTenantId("omp"));
        return SingleResult.success("修改成功", "");
    }


    @UserSessionRequired
    @GetMapping("/wms/getSet")
    @ApiOperation(value = "获取wms全局设置", notes = "获取wms全局设置")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WmsSystemEntity.class))
    public SingleResult getWmsSet(Long storageId) {
        //角色类型校验
        getTenantId("wms");
        return SingleResult.success("查询成功", systemSetService.getWmsSet(storageId));
    }


    @UserSessionRequired
    @PutMapping("/wms/set")
    @ApiOperation(value = "wms修改全局设置", notes = "wms修改全局设置")
    public SingleResult wmsSet(@RequestBody @Validated WmsSystemEntity req) {
        //角色类型校验
        getTenantId("wms");
        systemSetService.wmsSet(req, req.getStorageId());
        return SingleResult.success("修改成功", "");
    }


    @UserSessionRequired
    @GetMapping("/oms/getSet")
    @ApiOperation(value = "获取oms计量单位设置", notes = "获取oms计量单位设置")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = OmsSystemEntity.class))
    public SingleResult getOmsSet() {
        return SingleResult.success("查询成功", systemSetService.getOmsSet(getCompanyId()));
    }


    @UserSessionRequired
    @PutMapping("/oms/set")
    @ApiOperation(value = "oms修改计量单位设置", notes = "oms修改计量单位设置")
    public SingleResult omsSet(@RequestBody @Validated OmsSystemEntity req) {
        systemSetService.omsSet(req, getCompanyId());
        return SingleResult.success("修改成功", "");
    }


}
